package com.zqx.dryproxy.client;

import com.zqx.dryproxy.abstractobject.AbstractDocumentDao;
import com.zqx.dryproxy.abstractobject.AbstractUserDao;
import com.zqx.dryproxy.handler.DaoLogHandler;
import com.zqx.dryproxy.realobject.DocumentDao;
import com.zqx.dryproxy.realobject.UserDao;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class Client {
    public static void main(String[] args) {
        InvocationHandler handler = null;
        AbstractUserDao userDao =new UserDao();
        handler = new DaoLogHandler(userDao);
        AbstractUserDao proxy = (AbstractUserDao)Proxy.newProxyInstance(AbstractUserDao.class.getClassLoader(),new Class[]{AbstractUserDao.class},handler);
        proxy.findUserById("张玉娜");//调用代理对象的业务方法，不要问张玉娜是谁，知道她是女神就好了
        System.out.println("==================================================================");

        AbstractDocumentDao documentDao = new DocumentDao();
        handler = new DaoLogHandler(documentDao);
        AbstractDocumentDao proxy2 = (AbstractDocumentDao)Proxy.newProxyInstance(AbstractDocumentDao.class.getClassLoader(),new Class[]{AbstractDocumentDao.class},handler);
        proxy2.deleteDocumentById("DOO2");//调用代理对象的业务方法
    }
}
